package net.xiaoyu233.mitemod.miteite.render.entity.model;

import net.minecraft.*;
import net.xiaoyu233.mitemod.miteite.entity.EntityHellWither;
import org.lwjgl.opengl.GL11;

public class EntityHellWitherModel extends bbo {

    private bcu[] bodyParts;
    private bcu[] heads;


    public EntityHellWitherModel(){
        this.t = 64;//纹理图的长
        this.u = 64;//纹理图的宽

        this.bodyParts = new bcu[3];
        this.bodyParts[0] = new bcu(this, 0, 16);
        this.bodyParts[0].a(-10.0F, 3.9F, -0.5F, 20, 3, 3);
        this.bodyParts[1] = (new bcu(this)).b(this.t, this.u);
        this.bodyParts[1].a(-2.0F, 6.9F, -0.5F);
        this.bodyParts[1].a(0, 22).a(0.0F, 0.0F, 0.0F, 3, 10, 3);
        this.bodyParts[1].a(24, 22).a(-4.0F, 1.5F, 0.5F, 11, 2, 2);
        this.bodyParts[1].a(24, 22).a(-4.0F, 4.0F, 0.5F, 11, 2, 2);
        this.bodyParts[1].a(24, 22).a(-4.0F, 6.5F, 0.5F, 11, 2, 2);
        this.bodyParts[2] = new bcu(this, 12, 22);
        this.bodyParts[2].a(0.0F, 0.0F, 0.0F, 3, 6, 3);

        this.heads = new bcu[5];
        this.heads[0] = new bcu(this, 0, 0);
        this.heads[0].a(-4.0F, -4.0F, -4.0F, 8, 8, 8);
        this.heads[1] = new bcu(this, 32, 0);
        this.heads[1].a(-4.0F, -4.0F, -4.0F, 6, 6, 6);
        this.heads[1].c = -8.0F;
        this.heads[1].d = 4.0F;
        this.heads[2] = new bcu(this, 32, 0);
        this.heads[2].a(-4.0F, -4.0F, -4.0F, 6, 6, 6);
        this.heads[2].c = 10.0F;
        this.heads[2].d = 4.0F;
        this.heads[3] = new bcu(this, 32, 0);
        this.heads[3].a(-4.0F, -4.0F, -4.0F, 6, 6, 6);
        this.heads[3].c = 0;
        this.heads[3].d = 12.0F;
        this.heads[4] = new bcu(this, 32, 0);
        this.heads[4].a(-4.0F, -4.0F, -4.0F, 6, 6, 6);
        this.heads[4].c = 0;
        this.heads[4].d = 12.0F;

    }


    public int a() {
        return 32;
    }

    public void a(Entity var1, float var2, float var3, float var4, float var5, float var6, float var7) {
        this.a(var2, var3, var4, var5, var6, var7, var1);
        // 应用模型缩放（如果需要）
        if (var1 instanceof EntityHellWither) {
            EntityHellWither hellWither = (EntityHellWither)var1;
            float scale = hellWither.getCurrentScale();
            GL11.glScalef(scale, scale, scale);
        }

        for(bcu var11 : this.bodyParts) {
            var11.a(var7);
        }

        for(bcu var15 : this.heads) {
            var15.a(var7);
        }
        // 恢复缩放
        if (var1 instanceof EntityHellWither) {
            EntityHellWither hellWither = (EntityHellWither)var1;
            float scale = hellWither.getCurrentScale();
            GL11.glScalef(1.0F / scale, 1.0F / scale, 1.0F / scale);
        }

    }

    public void a(float var1, float var2, float var3, float var4, float var5, float var6, Entity var7) {
        float var8 = MathHelper.cos(var3 * 0.1F);
        this.bodyParts[1].f = (0.065F + 0.05F * var8) * (float)Math.PI;
        this.bodyParts[2].a(-2.0F, 6.9F + MathHelper.cos(this.bodyParts[1].f) * 10.0F, -0.5F + MathHelper.sin(this.bodyParts[1].f) * 10.0F);
        this.bodyParts[2].f = (0.265F + 0.1F * var8) * (float)Math.PI;
        this.heads[0].g = var4 / (180F / (float)Math.PI);
        this.heads[0].f = var5 / (180F / (float)Math.PI);
        // 修改第4和第5个头的旋转逻辑，使其围绕凋零对称旋转
        if (var7 instanceof EntityHellWither) {
            EntityHellWither hellWither = (EntityHellWither)var7;

            // 第4个头的旋转
            float rotation4 = hellWither.getFourthHeadRotation() * (float)Math.PI / 180.0F;
            float radius = 16.0F; // 旋转半径
            float xOffset4 = MathHelper.cos(rotation4) * radius;
            float zOffset4 = MathHelper.sin(rotation4) * radius;

            this.heads[3].c = xOffset4;
            this.heads[3].e = zOffset4;
            this.heads[3].g = rotation4 + (float)Math.PI;

            // 第5个头的旋转（与第4个头对称）
            float rotation5 = hellWither.getFifthHeadRotation() * (float)Math.PI / 180.0F;
            float xOffset5 = MathHelper.cos(rotation5) * radius;
            float zOffset5 = MathHelper.sin(rotation5) * radius;

            this.heads[4].c = xOffset5;
            this.heads[4].e = zOffset5;
            this.heads[4].g = rotation5 + (float)Math.PI;
        } else {
            // 默认行为
            this.heads[3].g = MathHelper.cos(var3 * 0.05F) * 0.1F;
            this.heads[3].f = MathHelper.sin(var3 * 0.05F) * 0.05F;
            this.heads[4].g = MathHelper.cos(var3 * 0.05F + (float)Math.PI) * 0.1F; // 对称旋转
            this.heads[4].f = MathHelper.sin(var3 * 0.05F) * 0.05F;
        }
    }

    public void a(EntityLiving var1, float var2, float var3, float var4) {
        EntityWither var5 = (EntityWither)var1;

        for(int var6 = 1; var6 < 3; ++var6) { // 只处理前3个头
            this.heads[var6].g = (var5.a(var6 - 1) - var1.renderYawOffset) / (180F / (float)Math.PI);
            this.heads[var6].f = var5.c(var6 - 1) / (180F / (float)Math.PI);
        }

    }
}
